<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    /* 
      https://leetcode-cn.com/problems/single-number/
      思路：https://leetcode-cn.com/problems/single-number/solution/hua-jie-suan-fa-136-zhi-chu-xian-yi-ci-de-shu-zi-b/
     */
    let nums = [2,2,1];

    // 1、利用库函数，是下面版本的优化
    function singleNumber(nums) {
      return nums.reduce((a, b) => a ^ b);
    }

    // 2、遍历+异或运算
    // function singleNumber(nums) {
    //   let res = 0;
    //   for (let num of nums) {
    //     res ^= num;
    //   }
    //   return res;
    // }
    console.log(singleNumber(nums));
  </script>
</body>
</html>